package com.imagination.applet.controller.api;

import com.imagination.applet.controller.api.request.VirtualIdentitySubmitParam;
import com.imagination.applet.controller.api.request.cropReq;
import com.imagination.applet.controller.api.response.UserPhotosResponse;
import com.imagination.applet.controller.web.configuration.UserHolder;
import com.imagination.applet.domain.photo.model.UserPhoto;
import com.imagination.applet.domain.photo.model.UserPhotosResult;
import com.imagination.applet.domain.photo.service.UserPhotoCommandService;
import com.imagination.applet.infrastructure.common.RestResponse;
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/user-photos")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
//@Tag(name = "用户照片服务")
public class UserPhotosController {
    private final UserPhotoCommandService userPhotoCommandService;

    @PostMapping
//    @Operation(summary = "上传用户照片")
    public RestResponse<UserPhotosResponse> addImage(@RequestPart List<MultipartFile> photos, cropReq cropReq) {
        Long userId = UserHolder.getUserId();
        UserPhotosResult result = userPhotoCommandService.addPhotos(userId, photos, cropReq);
        return RestResponse.ok(UserPhotosResponse.of(result));
    }

    @GetMapping
//    @Operation(summary = "用户照片列表")
    public RestResponse<Object> userPhotos() {
        List<UserPhoto> list = userPhotoCommandService.userPhotos();
        return RestResponse.ok(list);
    }

    @PostMapping(value = "/del")
//    @Operation(summary = "删除用户照片")
    public RestResponse<Void> removeImage(@RequestBody VirtualIdentitySubmitParam param) {
        Long userId = UserHolder.getUserId();
        userPhotoCommandService.removePhoto(userId, param.getId());
        return RestResponse.ok();
    }
}
